package com.rogchen.social.oauthserver.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;

@Controller
public class LoginController {

    // Login form
    @GetMapping("login")
    public String login() {
        return "login.html";
    }

    // Login form with error
    @RequestMapping("login-error.html")
    public String loginError(Model model) {
        model.addAttribute("loginError", true);
        return "login.html";
    }

    @GetMapping("/api/{id}")
    @ResponseBody
    public String api(@PathVariable String id) {
        return "api" + id;
    }


    @GetMapping("/user")
    @ResponseBody
    public Principal user(Principal pri) {
        System.out.println(pri);
        return pri;
    }
}